import 'package:flutter/material.dart';
import 'package:flutter01/GetX/getController/counterController.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';


class GetControllerPage extends StatefulWidget {
  const GetControllerPage({super.key});

  @override
  State<GetControllerPage> createState() => _GetControllerPageState();
}

class _GetControllerPageState extends State<GetControllerPage> {

  //获取GetController对象
  //可以理解为spring中的AutoWired
  CounterController counterController = Get.find();

  @override
    Widget build(BuildContext context) {
      return Scaffold(
          appBar: AppBar(
            title: const Text("Flutter APP"),
          ),
          body: Center(
            child: Column(
              children: [
                Obx(() => Text("${counterController.counter}",style: const TextStyle(fontSize: 40))),
                ElevatedButton(onPressed: (){
                  counterController.dec();
                }, child: const Text("计数-1"))
              ],
            )
          )
      );
    }
}




